<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 数组的遍历
        // forEach for in for of         
        let arr = [1, 2, 3, 4, 5]
        arr.forEach((val, index) => {
            console.log(val, index)
        })
        console.log('----------------')

        for (let key in arr) {
            console.log(key, arr[key])
        }
        console.log('----------------')

        for (let key of arr) {
            console.log(key)
        }
        console.log('----------------')

        // filter 过滤
        console.log(arr.filter((val, index) => val > 3))
        console.log('----------------')

        //合并
        let arr2 = [6, 7, 8, 9, 10]
        console.log(arr.concat(arr2))
        console.log([...arr, ...arr2])
        console.log('----------------')

        //去重
        let arr3 = [22, 33, 22, 33, 44, 55, 44, 66]
        console.log([...new Set(arr3)])
        console.log(Array.from(new Set(arr3)))
        console.log(arr3.reduce((pre, cur) => pre.includes(cur) ? pre : [...pre, cur], []))
        console.log(arr3.reduce((pre, cur) => pre.indexOf(cur) === -1 ? [...pre, cur] : pre, []))
        console.log('----------------')

        //冒泡
        console.log(arr.sort(function (a, b) {
            return a - b
        }))
        console.log('----------------')

        //求和
        console.log(arr.reduce((pre, cur) => pre + cur))
        console.log('----------------')

        //映射
        console.log(arr.map((val, index) => val * 1.2).map((val, index) => val * 0.8))
        console.log('----------------')

        //扁平化数组
        let arr4 = [1, 2, 3, 4, [99, 88, 77, [55, 66]], 33, 22]
        console.log(arr4.flat(Infinity))

        function flatter(arr) {
            return arr.reduce((pre, cur) => pre.concat(Array.isArray(cur) ? flatter(cur) : cur), [])
        }
        console.log(flatter(arr4))

        console.log('数组结束  ----------------  对象')

        //class
        class Person {
            constructor(name, age, car) {
                this.name = name;
                this.age = age;
                this.car = car;
            }
            havefun() {
                console.log('havefun')
            }
        }

        class Son extends Person {
            constructor(name, age, house) {
                super(name, age);
                this.house = house;
            }
            ride() {
                console.log('我喜欢摩拜')
            }
        }

        var zs = new Son('zs', 18, '天桥')
        console.log(zs)
        zs.havefun()
        console.log('----------------')

        let obj1 = {
            name: 'zs',
            age: 18,
        }
        let obj2 = {
            car: 'mobike',
            house: 'door'
        }

        console.log(Object.assign(obj1, obj2))
        console.log({ ...obj1, ...obj2 })
        console.log('----------------')



        console.log('对象结束  ----------------  函数')
        let sbo = Symbol()
        let fn1 = () => { }
        let obj3 = {
            name: 'zs',
            fn() { },
            fn1,
            [sbo]: () => { }
        }
        console.log(obj3)
    </script>
</body>

</html>